#
# @lc app=leetcode.cn id=599 lang=python3
#
# [599] 两个列表的最小索引总和
#

# @lc code=start
class Solution:
    def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
        d1 = dict()
        for i in range(len(list1)):
            d1[list1[i]] = i
        l = []
        for i in range(len(list2)):
            if d1.__contains__(list2[i]):
                sum = d1[list2[i]] + i
                if not l:
                    l.append([sum, [list2[i]]])
                else:
                    if sum < l[0][0]:
                        l.insert(0, [sum, [list2[i]]])
                    elif sum == l[0][0]:
                        l[0][1].append(list2[i])
        return l[0][1]

# @lc code=end

